% TABLE3A.M

clear;
randn('seed',123)

% Table 3a: Daily regular gasoline price, 2003-2008
load data3a.txt;
nobs=data3a(:,1); % Number of news announcements
n=length(nobs);   % Number of mining trials left 
vary=data3a(:,2); % Variance of dependent variable (different for each
                  % regression as sample differs)
varx=data3a(:,3); % Variance of the n individual regressors

nrep=100000;                           % Simulation trials -> inf
for i=1:nrep;

    tstat=zeros(n,1);
    for j=1:n
        y=sqrt(vary(j,1)).*randn(nobs(j,1),1);
        x=sqrt(varx(j,1)).*randn(nobs(j,1),1);
        tstat(j,1)=ols(y,[ones(nobs(j,1),1) x]);
    end;
    
    % Take supremum over n t-statistics for each trial i:
    tmax(i,1)=max(tstat);
    clear y x tstat;
end;

% Compute 5% and 10% one-sided critical values of the distribution of the 
% sup-t-statistic allowing for data mining
%disp([n prctile(tmax,(1-0.05)*100)])
%disp([n prctile(tmax,(1-0.10)*100)])

% P-values
sum(sort(tmax)>0.33)/length(tmax)

